<?php

	define('S_SU',256);
	define('S_CHGPW',128);
	define('S_ANA',64);
	define('S_ENABLED',32);
	define('S_FAC',4);
	define('S_ADM',2);
	define('S_USER',1);

	function setSecurityToken($tok) {
		global $secToken;
		$secToken = $tok;
	}
	
	function getSecurityToken(){
		global $secToken;
		return $secToken;
	}
	


	function isSU(){
		global $secToken;
		if((S_SU & $secToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}
	
	function chgPwd() {
		global $secToken;
		if((S_CHGPW & $secToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}
	
	function isBlocked() {
		global $secToken;
		if((S_ENABLED & $secToken) == 0)
			return 1;
		else 
			return 0;
		
	}
	
	function isEnabled() {
		global $secToken;
		if((S_ENABLED & $secToken) == 0)
			return 0;
		
		else
			return 1;
		
	}

	function isAnalyst() {
		global $secToken;
		if((S_ANA & $secToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}
	
	function isFac() {
		global $secToken;
		if((S_FAC & $secToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}	
	
	function isUser() {
		global $secToken;
		if((S_USER & $secToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}
	
	function isAdm() {
		global $secToken;
		if((S_ADM & $secToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}	
	
	function credentialsOK($pgmToken){
		global $secToken;
		if(($secToken & $pgmToken) == 0)
			return 0;
		
		else 
			return 1;
		
	}
	
	function chkLogin($script){
		if( empty($_SESSION['security_token'])){
			$_SESSION['nextScript'] = $script;
			header("Location: " . 'login2.php');
		}else 
			setSecurityToken($_SESSION['security_token']);
		
	}
	function deleteSessionVars(){
		$_SESSION = array();
	}	
	
	function logOut(){
		deleteSessionVars();
	}
?>
